

/** 
 * 通过 营业额 计算划卡 
 * */
export function countCardSwipe(turnover?: any[], project?: any[], cardType?: any[]) {
    return turnover
        ?.map?.(e => getTurnoverPurpose(e['耗卡项目'], project) * getCardTypeCoefficient(cardType, e['耗卡卡项类型']))
        ?.reduce?.((acc, cur) => acc + (cur || 0), 0) || 0;
}

/** 获取指定项目的划卡金额 */
const getTurnoverPurpose = (purpose?: string, project?: any[]) => {
    const p = project?.filter(e => e['项目名称'] === purpose)[0]; if (!p) return 0;
    return p['划卡金额'] || 0;
}

/** 系数 */
const getCardTypeCoefficient = (cardType?: any[], type?: string) => {
    const t = cardType?.filter(e => e['耗卡卡项类型'] === type)[0]; if (!t) return 0;
    return t['耗卡系数'] || 0;
}